import { getInfo, getLoginInfo } from '@/api/index-web'
import { storage } from '@/utils/storage';
import { showModal } from './message';

function gotoLogin() {
  uni.reLaunch({
    url: '/pages/index/Login'
  })
}

export const checkInfo = async () => {
  let token = storage.get('token')
  if(token) {
    let res = await getInfo()
    if(res.c != 200) {
      showModal(m, '提示')
      return
    }
    storage.set('LoginInfo', res.d)
    let res1 = await getLoginInfo()
    if(res.c != 200) {
      showModal(m, '提示')
      return
    }
    storage.set('UserInfo', res1.d)
  } else {
    showModal('获取用户信息失败，请重新登录', '提示', gotoLogin, gotoLogin)
  }
}